package com.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.basic.dao.AdminDao;
import com.basic.domain.Admin;
import com.basic.service.IAdminService;
import com.basic.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminDao, Admin> implements IAdminService {

    @Autowired
    private AdminDao adminDao;

    @Override
    public Response checkLogin(Admin admin) {

        String mobile = admin.getMobile();
        String password = admin.getPassword();

        if (mobile == null || password == null) {
            return new Response(1, "手机号或密码不能为空");
        }

        //LambdaQueryWrapper<Admin> lqw = new LambdaQueryWrapper<>();
        QueryWrapper where = new QueryWrapper();
        where.select("password").eq("mobile", mobile);
        Admin adminInfo = adminDao.selectOne(where);
        boolean flat =  password.equals(adminInfo.getPassword());
        if  (flat) {
            return new Response(0, "登陆成功");
        }
        return new Response(1, "登陆失败");
    }
}
